package com.ruoyi.lock.service.impl;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.lock.domain.AAddress;
import com.ruoyi.lock.mapper.AAddressMapper;
import com.ruoyi.lock.service.IAAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 地址管理Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-03-09
 */
@Service
public class AAddressServiceImpl implements IAAddressService 
{
    @Autowired
    private AAddressMapper aAddressMapper;

    /**
     * 查询地址管理
     * 
     * @param id 地址管理主键
     * @return 地址管理
     */
    @Override
    public AAddress selectAAddressById(Long id)
    {
        return aAddressMapper.selectAAddressById(id);
    }

    /**
     * 查询地址管理列表
     * 
     * @param aAddress 地址管理
     * @return 地址管理
     */
    @Override
    @DataScope(deptAlias = "d")
    public List<AAddress> selectAAddressList(AAddress aAddress)
    {
        return aAddressMapper.selectAAddressList(aAddress);
    }

    @Override
    @DataScope(deptAlias = "c")
    public List<AAddress> selectXY(AAddress aAddress)
    {
        return aAddressMapper.selectXY(aAddress);
    }

    /**
     * 新增地址管理
     * 
     * @param aAddress 地址管理
     * @return 结果
     */
    @Override
    public int insertAAddress(AAddress aAddress)
    {
        aAddress.setUserId(SecurityUtils.getUserId());
        aAddress.setCreateBy(SecurityUtils.getUsername());
        aAddress.setCreateTime(DateUtils.getNowDate());
        Long deptId = SecurityUtils.getDeptId();
        aAddress.setDeptId(deptId);
        return aAddressMapper.insertAAddress(aAddress);
    }

    /**
     * 修改地址管理
     * 
     * @param aAddress 地址管理
     * @return 结果
     */
    @Override
    public int updateAAddress(AAddress aAddress)
    {
        Long userId = SecurityUtils.getUserId();
        aAddress.setUpdateBy(String.valueOf(userId));
        aAddress.setUpdateTime(DateUtils.getNowDate());
        Long deptId = SecurityUtils.getDeptId();
        aAddress.setDeptId(deptId);
        return aAddressMapper.updateAAddress(aAddress);
    }

    /**
     * 批量删除地址管理
     * 
     * @param ids 需要删除的地址管理主键
     * @return 结果
     */
    @Override
    public int deleteAAddressByIds(Long[] ids)
    {
        return aAddressMapper.deleteAAddressByIds(ids);
    }

    /**
     * 删除地址管理信息
     * 
     * @param id 地址管理主键
     * @return 结果
     */
    @Override
    public int deleteAAddressById(Long id)
    {
        return aAddressMapper.deleteAAddressById(id);
    }
}
